const Product = require("../../model/manage/Product");

module.exports = {
  async list(req, res) {//列表
    let rec = req.query;
    let data = await Product.list(rec.page, rec.count, rec.type, rec.order);

    if (data.code == 200) {
      res.success("获取成功", data.data);
    } else {
      res.error(data.msg);
    }
  },
  async detail(req, res) {//详情
    let id = req.params.id;
    let data = await Product.detail(id);

    if (data.code == 200) {
      res.success("获取成功", data.data);
    } else {
      res.error(data.msg);
    }
  },
  async edit(req, res) {//保存
    let data = req.body;

    let result = await Product.edit(data);

    if(result.code == 200) {
        res.success('保存成功', {});
    }else {
        res.error(result.msg);
    }
  },
  async remove(req, res) {//软删除
      let id = req.params.id;

      let result = await Product.remove(id);

      if(result.code == 200){
        res.success("删除成功", result.data);
      }else {
        res.error(res.msg);
      }
  },
  async add(req, res) {//添加
    let data = req.body;

    let result = await Product.add(data);

    if(result.code == 200) {
        res.success("添加成功", {})
    }else{
        res.error(res.msg);
    }
  }
};
